#ifndef MESSAGE_DISPATCHER_H
#define MESSAGE_DISPATCHER_H

#include <set>
#include "Telegram.h"
#include "Entity/BaseEntity.h"

//==============================================================================
// message dispatcher class for fsm. Singleton class
class MessageDispatcher {
public:
	static MessageDispatcher* Instance();

    // send message, add to queue if should be delayed
	void dispatchMessage(double p_delay, 
							int p_sender,
							int p_receiver,
							int p_message,
							void* p_extraInfo);



    // should be called in update loop, sends telegrams in queue
	void dispatchDelayedMessages();



private:
	// message queue for delayed messages
	std::set<Telegram> m_messageQueue;
	


	// call p_receiver's message handling function on p_message
	void dischargeMessage(BaseEntity* p_receiver, const Telegram& p_message);



	MessageDispatcher() {}
	MessageDispatcher& operator=(const MessageDispatcher&);
	MessageDispatcher(const MessageDispatcher&);
};
//==============================================================================

#endif